<?php class complete extends Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function truncate(){
    	return $this->db->truncate('complete');
    }
    
    
    function insert(){
       $this->name = $_POST['name'];
       $this->codes = '0';
       $this->mod_id = $_POST['mod_id'];
       $cates = strlen($_POST['category_ids']);
       $category = substr($_POST['category_ids'],0,$cates-1);

       $this->category_ids = $category;
       $this->createtime = time();
       $re = $this->select(array('name'=>$_POST['name']));
       if(count($re)==0){
         $this->db->insert('complete',$this);
         $result = 1;
       }else{
         $result = 0;
       }
       return $result;
    }
    
    function select($id,$num="",$offset=""){
       $this->db->limit($num,$offset);	
       if($id!=""){
       	  $this->db->where($id);
       }
       $query = $this->db->get('complete');
       $result = $query->result(); 
       return $result;
    }
    
    function select_array($array){
        $this->db->where($array);
        $query = $this->db->get('complete');
        $result = $query->result(); 
        return $result;
    }
    
    function update($id){
       $this->name = $_POST['name'];
       $this->codes = $_POST['codes'];
       $cates = strlen($_POST['category_ids']);
       $category = substr($_POST['category_ids'],0,$cates-1);
       $this->category_ids = $category;
       $result = $this->db->update('complete',$this,array('complete_id'=>$id));
       return $result;
    }
    
    function del($id){
       $result = $this->db->delete('complete',array('complete_id'=>$id));
       return $result;
    }
}